package test.shortestpath;

import java.util.List;

public class Graph {

	private List<Vertex> vertices;
	
	private List<Edge> edges;
	
	public Graph(List<Vertex> vertices, List<Edge> edges) {
		super();
		this.vertices = vertices;
		this.edges = edges;
	}

	public void addEdge(Edge edge) {
		edges.add(edge);
		if (!vertices.contains(edge.getVertex1())) {
			throw new IllegalArgumentException("Vertex " + edge.getVertex1().getId() + " is not contained");
		}
		if (!vertices.contains(edge.getVertex2())) {
			throw new IllegalArgumentException("Vertex " + edge.getVertex2().getId() + " is not contained");
		}
		edge.getVertex1().getNeighbors().put(edge.getVertex2(), edge);
		edge.getVertex2().getNeighbors().put(edge.getVertex1(), edge);
	}

	public Vertex getVertex(int id) {
		for (Vertex v : vertices) {
			if (v.getId() == id) {
				return v;
			}
		}
		return null;
	}
	
	public List<Vertex> getVertices() {
		return vertices;
	}

	public void setVertices(List<Vertex> vertices) {
		this.vertices = vertices;
	}

	public List<Edge> getEdges() {
		return edges;
	}

	public void setEdges(List<Edge> edges) {
		this.edges = edges;
	}
	
}
